package com.xbts.web.controller.cloud;

import com.xbts.common.annotation.Log;
import com.xbts.common.core.controller.BaseController;
import com.xbts.common.core.domain.AjaxResult;
import com.xbts.common.core.page.TableDataInfo;
import com.xbts.common.enums.BusinessType;
import com.xbts.common.exception.ServiceException;
import com.xbts.common.utils.SecurityUtils;
import com.xbts.common.utils.poi.ExcelUtil;
import com.xbts.system.domain.CnOrderItem;
import com.xbts.system.domain.dto.CnOrderItemReviewDTO;
import com.xbts.system.enums.OrderStatusEnum;
import com.xbts.system.service.ICnOrderItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * 子订单Controller
 * @author xbts
 * @date 2023-08-03
 */
@Api("子订单")
@RestController
@RequestMapping("/system/order/item")
public class CnOrderItemController extends BaseController {

    @Autowired
    private ICnOrderItemService cnOrderItemService;

    /**
     * 查询子订单列表
     */
    @ApiOperation("查询子订单列表")
    @PreAuthorize("@ss.hasPermi('system:item:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody CnOrderItem cnOrderItem)     {
        startPage(cnOrderItem);
        List<CnOrderItem> list = cnOrderItemService.selectCnOrderItemList(cnOrderItem);
        return getDataTable(list);
    }


    /**
     * 统计子订单列表
     */
    @ApiOperation("统计子订单列表")
    @PreAuthorize("@ss.hasPermi('system:item:list')")
    @PostMapping("/statisticsList")
    public AjaxResult statisticsList(@RequestBody CnOrderItem cnOrderItem)     {
        return success(cnOrderItemService.statisticsList(cnOrderItem));
    }

    /**
     * 导出子订单列表
     */
    @ApiOperation("导出子订单列表")
    @PreAuthorize("@ss.hasPermi('system:item:export')")
    @Log(title = "子订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response,@RequestBody CnOrderItem cnOrderItem) {
        List<CnOrderItem> list = cnOrderItemService.selectCnOrderItemList(cnOrderItem);
        ExcelUtil<CnOrderItem> util = new ExcelUtil<CnOrderItem>(CnOrderItem.class);
        util.exportExcel(response, list, "子订单数据");
    }

    /**
     * 获取子订单详细信息
     */
    @ApiOperation("获取子订单详细信息")
    @ApiImplicitParam(name = "orderItemId", value = "子订单ID", required = true, dataType = "String", paramType = "path", dataTypeClass=String.class)
    @PreAuthorize("@ss.hasPermi('system:item:query')")
    @GetMapping(value = "/{orderItemId}")
    public AjaxResult getInfo(@PathVariable("orderItemId") String orderItemId) {
        return success(cnOrderItemService.selectCnOrderItemByOrderItemId(orderItemId));
    }

    /**
     * 新增子订单
     */
    @ApiOperation("新增子订单")
    @PreAuthorize("@ss.hasPermi('system:item:add')")
    @Log(title = "子订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody CnOrderItem cnOrderItem) {
        return toAjax(cnOrderItemService.insertCnOrderItem(cnOrderItem));
    }

    /**
     * 修改子订单
     */
    @ApiOperation("修改子订单")
    @PreAuthorize("@ss.hasPermi('system:item:edit')")
    @Log(title = "子订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody CnOrderItem cnOrderItem) {
        return toAjax(cnOrderItemService.updateCnOrderItem(cnOrderItem));
    }

    /**
     * 删除子订单
     */
    @ApiOperation("删除子订单")
    @ApiImplicitParam(name = "orderItemIds", value = "子订单ID集合", required = true, dataType = "String", paramType = "path", dataTypeClass=String.class)
    @PreAuthorize("@ss.hasPermi('system:item:remove')")
    @Log(title = "子订单", businessType = BusinessType.DELETE)
	@PostMapping("/batchDelete")
    public AjaxResult batchDelete(@RequestBody List<String> orderItemIds) {
        return toAjax(cnOrderItemService.deleteCnOrderItemByOrderItemIds(orderItemIds));
    }

    /**
     * 云服务管理-审核列表
     * @return
     */
    @PostMapping("/reviewList")
    public TableDataInfo reviewList(@RequestBody CnOrderItemReviewDTO cnOrderItem){
        startPage(cnOrderItem);
        return getDataTable(cnOrderItemService.reviewList(cnOrderItem));
    }

}
